package com.dji.GSDemo.GaodeMap.service;

import com.dji.GSDemo.GaodeMap.entity.FlyingPath;
import com.dji.GSDemo.GaodeMap.entity.Task;
import com.dji.GSDemo.GaodeMap.entity.Waypoint;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public  class MockMissionService extends MissionService {


    //模拟获取任务列表
    String mockTaskFromRemote() {
        List<Task> tasks = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            Task mockTask = new Task();
            mockTask.setDeviceId(i + "");
            mockTask.setCreatetime(new Date());
            mockTask.setFlyingpathId(i);
            mockTask.setTaskId(i);
            mockTask.setTaskName("test-" + i);
            tasks.add(mockTask);
        }
        return new Gson().toJson(tasks);
    }

    //模拟获取点列表
    String mockWayPointsFromRemote() {
        List<Waypoint> waypointList = new ArrayList<>();
        double baseLatitude = 30.5111300000, baseLongitude = 114.4347550000;
        for (int i = 0; i < 20; i++) {
            Waypoint waypoint = new Waypoint();
            waypoint.setLongitude(baseLongitude + i);
            waypoint.setLatitude(baseLatitude + i);
            waypoint.setAltitude(20f);
            waypointList.add(waypoint);
        }
        return new Gson().toJson(waypointList);
    }

    /*
     关与任务列表的操作
     */
    //模拟json转taskList
    @Override
    public List<Task> getTaksListFromJson(String json) {
        List<Task> tasks = new Gson().fromJson(json.toString(), new TypeToken<List<Task>>() {
        }.getType());
        return tasks;
    }

    // 模拟获取任务列表
    @Override
    public List<Task> getTaskList(int page, int limit, int finishStatus) {
        return getTaksListFromJson(mockTaskFromRemote());
    }

    //模拟把json字符串转成 waypointList
    @Override
    public List<Waypoint> getWaypointListFromJson(String json) {
        List<Waypoint> waypoints = new Gson().fromJson(json, new TypeToken<List<Waypoint>>() {
        }.getType());
        return waypoints;
    }

    //模拟获取waypointList
    @Override
    public List<Waypoint> getWaypointList(int pathId) {
        return getWaypointListFromJson(mockWayPointsFromRemote());
    }

    //模拟获取路径信息
    public FlyingPath getFlyingPath(int pathId) {
      FlyingPath flyingPath=new FlyingPath();
      flyingPath.setName("MOCK");
      flyingPath.setAutoFlightSpeed(12f);
      flyingPath.setCreateTime(new Date());
      flyingPath.setFinishedAction("GO-HOME");


      return flyingPath;

    }
}
